<?php

App::uses('AppModel', 'Model');
App::uses('BrValidation', 'Localized.Validation');

/**
 * Endereco Model
 *
 * @property Cidade $Cidade
 * @property Empresa $Empresa
 * @property Funcionario $Funcionario
 */
class Endereco extends AppModel {

	var $name = 'Endereco';
/**
 * Validation rules
 *
 * @var array
 */
	public $validate = array(
		'rua' => array(
				'notempty' => array(
						'rule' => array('notempty'),
						'message' => 'Informe o local onde a empresa está situada.',
						//'allowEmpty' => false,
						//'required' => false,
						//'last' => false, // Stop validation after this rule
						//'on' => 'create', // Limit validation to 'create' or 'update' operations
				),
		),
		'numero' => array(
			'numeric' => array(
				'rule' => array('numeric'),
				'message' => 'O campo deve conter apenas números.',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'bairro' => array(
			'notempty' => array(
				'rule' => array('notempty'),
				'message' => 'Informe o bairro da empresa.',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'cep' => array(
			'valid' => array(
				'rule' => array('postal', null, 'br'),
				'message' => 'Digite um cep válido.',
				'allowEmpty' => false,
				'required' => true,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'complemento' => array(
			'notempty' => array(
				'rule' => array('notempty'),
				'message' => 'Informe um complemento ou referência.',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		/* 'cidade_id' => array(
			'numeric' => array(
				'rule' => array('numeric'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		), */
	);

	//The Associations below have been created with all possible keys, those that are not needed can be removed

/**
 * belongsTo associations
 *
 * @var array
 */
	public $belongsTo = array(
		'Cidade' => array(
			'className' => 'Cidade',
			'foreignKey' => 'cidade_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		)
	);
/**
 * hasOne associations
 *
 * @var array
 */
	public $hasOne = array(
		'Empresa' => array(
			'className' => 'Empresa',
			'foreignKey' => 'endereco_id',
			'dependent' => false,
			'conditions' => '',
			'fields' => '',
			'order' => ''
		),
		
		'Fornecedore' => array(
			'className' => 'Fornecedore',
			'foreignKey' => 'endereco_id',
			'dependent' => false,
			'conditions' => '',
			'fields' => '',
			'order' => ''
		),
			
		'Funcionario' => array(
			'className' => 'Funcionario',
			'foreignKey' => 'endereco_id',
			'dependent' => false,
			'conditions' => '',
			'fields' => '',
			'order' => ''
		),
			
		'Cliente' => array(
				'className' => 'Cliente',
				'foreignKey' => 'endereco_id',
				'dependent' => false,
				'conditions' => '',
				'fields' => '',
				'order' => ''
		),
	);
	
	
}
